package ECommerce;

public class CustomerList {
    private Customer[] c1;
    private int total; //用户数量
    public CustomerList(int totalCustomers){
        c1=new Customer[totalCustomers];
    }

   public boolean addCustomer(Customer customer){
        if(total<c1.length){
            c1[total++]=customer;
            return true;
        }else {
            return false;
        }
   }
    public boolean replaceCustomer(int index,Customer customer){
        if(index>=0&&index<total){
            c1[index]=customer;
            return true;
        }else {
            return false;
        }
    }
    public boolean deleteCustomer(int index){
        if(index>=0&&index<total){
            for (int i = index; i < total-1; i++) {
                c1[i]=c1[i+1];
            }
            c1[total-1]=null;
            total--;
            return true;
        }else {
            return false;
        }
    }
    public Customer[] getAllCustomers(){
        Customer[] cust=new Customer[total];
        for (int i = 0; i < cust.length; i++) {
            cust[i]=c1[i];
        }
        return cust;
    }
    public Customer getCustomer(int index){
        if(index<0||index>=total){
            return null;
        }
        return c1[index];
    }

    public int getTotal() {
        return total;
    }
}
